package service

import (
	"context"
	"fmt"

	pb "gitee.com/snitso/micro/api/example/v1"
	"gitee.com/snitso/micro/app/evaluation/internal/biz/example"
	"github.com/go-kratos/kratos/v2/middleware/tracing"
)

type ExampleService struct {
	pb.UnimplementedExampleServer

	uc *example.UseCase
}

func NewExampleService(uc *example.UseCase) *ExampleService {
	return &ExampleService{uc: uc}
}

func (s *ExampleService) SayHello(ctx context.Context, req *pb.GetExampleRequest) (*pb.GetExampleReply, error) {
	fmt.Println("SayHello")
	// 获取 traceID
	fmt.Println("traceID", tracing.TraceID()(ctx).(string))
	// 获取 spanID
	fmt.Println("spanID", tracing.SpanID()(ctx).(string))
	request := example.Request{
		Name: req.Name,
	}
	reply := s.uc.GetExample(ctx, &request)
	return &pb.GetExampleReply{Name: reply.Name}, nil
}
